<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>DOM文档对象模型</title>
</head>
<body>
<h1 id="h">倒计时</h1>
<input type="text" placeholder="请输入时间">
<button onclick="time()">开始倒计时</button>
<script>
    function time() {
        //利用id选择器获取元素的方式
        let h1 = document.getElementById('h');
        //利用选择器获取input元素的值
        let input = document.querySelector(`input`)
        //获取input输入框的值
        let num = input.value;
        let interval = setInterval(function () {
            h1.innerText = num;
            num--;
            if (num < 0) {
                clearInterval(interval);
                h1.innerText = '时间到';
            }
        },1000);
    }
</script>
</body>
</html>